﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:SqlMiM.Common.Controls">

    <Style x:Key="ExpanderToggleButton" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Background="{DynamicResource GradientVeryDarkToDarkness}" 
                            BorderBrush="{DynamicResource BrushLight}" BorderThickness="0,1,0,0" CornerRadius="4,4,0,0" VerticalAlignment="Top" Margin="0,0,0,0">

                        <Grid SnapsToDevicePixels="False" Background="Transparent">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="19" />
                            </Grid.ColumnDefinitions>

                            <Path Stroke="{DynamicResource Foreground}" StrokeThickness="3" HorizontalAlignment="Center"
                                  x:Name="arrow" Grid.Column="1" VerticalAlignment="Center" SnapsToDevicePixels="false"
                                  Data="M 1,1 L 4.5,7 L 8,1" RenderTransformOrigin="0.5,0.5">
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                        <SkewTransform AngleX="0" AngleY="0" />
                                        <RotateTransform Angle="-90" />
                                        <TranslateTransform X="0" Y="0" />
                                    </TransformGroup>

                                </Path.RenderTransform>
                            </Path>
                            <ContentPresenter HorizontalAlignment="Left" Margin="4,0,0,0" VerticalAlignment="Center"
                                SnapsToDevicePixels="True" Grid.Column="0" RecognizesAccessKey="True" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Duration="00:00:00.2000000"
                                          From="-90" To="0" BeginTime="00:00:00"
                                          Storyboard.TargetName="arrow" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Duration="00:00:00.2000000" From="0" To="-90" 
                                            BeginTime="00:00:00" Storyboard.TargetName="arrow"
                                            Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>

                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Stroke" TargetName="arrow" Value="AntiqueWhite" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Stroke" TargetName="arrow" Value="WhiteSmoke" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- NormalBrush is used as the Background for SimpleButton, SimpleRepeatButton -->
    <LinearGradientBrush x:Key="NormalBrush" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#EEE" Offset="0.0" />
        <GradientStop Color="#CCC" Offset="1.0" />
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="NormalBorderBrush" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#CCC" Offset="0.0" />
        <GradientStop Color="#444" Offset="1.0" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ExpanderArrowFill" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="White" Offset="0" />
        <GradientStop Color="#FFBFBFBF" Offset="0.5" />
        <GradientStop Color="#FF878787" Offset="1" />
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="ExpanderArrowHoverFill" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FFF0F8FE" Offset="0" />
        <GradientStop Color="#FFE0F3FE" Offset="0.3" />
        <GradientStop Color="#FF6FA7C5" Offset="1" />
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="ExpanderArrowPressedFill" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FFDCF0FA" Offset="0" />
        <GradientStop Color="#FFC5E6F7" Offset="0.2" />
        <GradientStop Color="#FF5690D0" Offset="1" />
    </LinearGradientBrush>


    <Style TargetType="{x:Type Expander}" >

        <Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <Border x:Name="Border" CornerRadius="5,5,5,5" SnapsToDevicePixels="True" BorderThickness="2" Background="{TemplateBinding Background}">

                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" x:Name="ContentRow" />
                            </Grid.RowDefinitions>


                            <ToggleButton Margin="0,0" Focusable="false" MinHeight="20" Style="{DynamicResource ExpanderToggleButton}"
                                              Content="{TemplateBinding Header}"
                                              ContentTemplate="{TemplateBinding HeaderTemplate}" ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                              Cursor="Hand" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}"
                                              FontStretch="{TemplateBinding FontStretch}" FontStyle="{TemplateBinding FontStyle}"
                                              FontWeight="{TemplateBinding FontWeight}" Foreground="{TemplateBinding Foreground}"
                                              HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                              IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                              OverridesDefaultStyle="True" />

                            <!-- the extra border here is required because Reveal doesn't account for margins -->
                            <c:Reveal  Grid.Row="1" x:Name="ContentReveal"  Duration="1000" 
                                  VerticalReveal="FromTopToBottom" HorizontalReveal="None" HorizontalAlignment="Stretch">
                                <Border HorizontalAlignment="Stretch">
                                    <Border BorderThickness="0.5,1,0,0" BorderBrush="#6000" Background="#10FFFFFF" >
                                        <Border BorderThickness="0,0,0.5,1" BorderBrush="#20FFFFFF">
                                            <ContentPresenter x:Name="ExpandSite" 
                                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                    Focusable="false" />
                                        </Border>
                                    </Border>
                                </Border>
                            </c:Reveal>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation BeginTime="0:0:0.2" Storyboard.TargetName="ContentReveal" Storyboard.TargetProperty="AnimationProgress"
                                                         Duration="0:0:0.2" To="1" DecelerationRatio="1" />

                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ContentReveal" Storyboard.TargetProperty="AnimationProgress" Duration="0:0:0.2" AccelerationRatio="1" />

                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>